class Solution {
    public int majorityElement(int[] nums) {
        if(nums.length == 1) {
            return nums[0];
        }
        int length = nums.length / 2;
        int ret = 0;
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        for(int num : nums) {
            if(!hashMap.containsKey(num)) {
                hashMap.put(num,1);
            } else {
                int ss = hashMap.get(num);
                if((ss+1) > length) {
                    ret = num;
                    break;
                }
                hashMap.put(num,ss+1);
            }
        }
        return ret;
    }
}